package com.gs.api.projects.bzapplets.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gs.api.projects.bzapplets.dao.BzWallpaperDao;
import com.gs.api.projects.bzapplets.entity.BzWallpaper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author guoyunfei on 2021/7/9 14:04
 * @className BzWallpaperDao
 * @description TODO
 * @Version 1.0
 */

@Service
public class BzWallpaperService  extends ServiceImpl<BzWallpaperDao,BzWallpaper> {

    @Autowired
    private BzWallpaperDao bzWallpaperDao;

    public PageInfo<BzWallpaper> pageInfo(BzWallpaper wallpaper,int pageNum,int pageSize,String order){

        PageHelper.startPage(pageNum, pageSize).setOrderBy(order);
        wallpaper.setIsDelete(1);
        final PageInfo<BzWallpaper> userPageInfo = new PageInfo<>(bzWallpaperDao.selectPage(wallpaper));
        return userPageInfo;
    }

    public PageInfo<BzWallpaper> pageInfoNew(BzWallpaper wallpaper,int pageNum,int pageSize,String order){
        PageHelper.startPage(pageNum, pageSize).setOrderBy(order);
        wallpaper.setIsDelete(1);
        final PageInfo<BzWallpaper> userPageInfo = new PageInfo<>(bzWallpaperDao.selectPageNew(wallpaper));
        return userPageInfo;
    }

    @Transactional
    public BzWallpaper selectByPrimaryKey(Integer id){
        BzWallpaper bzWallpaper = bzWallpaperDao.selectById(id);
        return bzWallpaper;
    }

    @Transactional
    public int updateBrowseCount(Map<String,Object> map){
        return bzWallpaperDao.updateBrowseCount(map);
    }

    @Transactional
    public int updateDownCount(Map<String,Object> map){
        return bzWallpaperDao.updateDownCount(map);
    }

    @Transactional
    public int updateShareCount(Map<String,Object> map){
        return bzWallpaperDao.updateShareCount(map);
    }

    @Transactional
    public int updateCollectionCount(Map<String,Object> map){
        return bzWallpaperDao.updateCollectionCount(map);
    }

    @Transactional
    public int updateSubCollectionCount(Map<String,Object> map){
        return bzWallpaperDao.updateSubCollectionCount(map);
    }

    @Transactional
    public int updateLikeCount(Map<String,Object> map){
        return bzWallpaperDao.updateLikeCount(map);
    }

    @Transactional
    public int updateSubLikeCount(Map<String,Object> map){
        return bzWallpaperDao.updateSubLikeCount(map);
    }


    public BzWallpaper getLimitOneRight(Map<String,Object> map){
        return bzWallpaperDao.getLimitOneRight(map);
    }
    public BzWallpaper getLimitOneLeft(Map<String,Object> map){
        return bzWallpaperDao.getLimitOneLeft(map);
    }

    public BzWallpaper upAndDownData(Map<String,Object> map){
        if(map.get("flag").toString().equals("left")){
            return bzWallpaperDao.getLimitOneLeft(map);
        }else if(map.get("flag").toString().equals("right")){
            return bzWallpaperDao.getLimitOneRight(map);
        }
        return null;
    }

    public List<Map<String,Object>> getHots(String appid){
        return bzWallpaperDao.getHots(appid);
    }


    public BzWallpaper getById(Integer id){
        return bzWallpaperDao.getById(id);
    }
}
